/**
 * Copyright (c) 2008, Keisuke Inoue, Syracuse Unviersity
 * All rights reserved.
 *
 */
package edu.syr.iis.web.controller;

import java.util.List;
import edu.syr.iis.web.model.DialogueActScheme;
import edu.syr.iis.web.model.DialogueActSchemeManager;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 * @author kinoue
 *
 */
public class DialogueActSchemeListController extends AbstractController
{

    DialogueActSchemeManager dialogueActSchemeManager;
    public static final String DEL_DASCH_ID = "deldaschemeid";
    public static final String DASCHS_KEY = "daschemes";
    private String successView;
        
    @Override
	public ModelAndView handleRequestInternal(HttpServletRequest request,
	    HttpServletResponse arg1) throws Exception
    {        
	/*
	 *  If DEL_DASCH_ID is specified, delete the item first.
	 */
	if (request.getParameter(DEL_DASCH_ID) != null
                && request.getParameter(DEL_DASCH_ID).trim().length() > 0) 
	{
            int conversationId = Integer.parseInt(request.getParameter(DEL_DASCH_ID));
            dialogueActSchemeManager.deleteDialogueActScheme(conversationId);
	}
	
	List<DialogueActScheme> dialogueActSchemes = dialogueActSchemeManager.getDialogueActSchemes();	
        return new ModelAndView(getSuccessView(), DASCHS_KEY, dialogueActSchemes);
    }

    public DialogueActSchemeManager getDialogueActSchemeMaager()
    {
        return dialogueActSchemeManager;
    }

    public void setDialogueActSchemeManager(DialogueActSchemeManager dialogueActSchemeManager)
    {
        this.dialogueActSchemeManager = dialogueActSchemeManager;
    }

    public String getSuccessView()
    {
        return successView;
    }

    public void setSuccessView(String successView)
    {
        this.successView = successView;
    }
    
    
}
